package com.zrc.japktool.apk.lib2cppTools.tools;

import com.zrc.japktool.util.TextUtils;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class Cmd {
    public Cmd() {
    }

    public static int run(String cmd) {
        return OSDetector.getOS() == OSDetector.win ? run_win(cmd) : -1;
    }

    public static int run_win(String cmd) {
        int ret = -1;
        List<String> commands = new ArrayList();
        commands.add("cmd.exe");
        commands.add("/c");
        commands.add(cmd);

        try {
            ret = ProcessHelper.processBuilderCommand(commands, (File)null);
        } catch (Exception var4) {
            var4.printStackTrace();
        }

        return ret;
    }

    private static int run_linux(String[] command, String outputFile) {
        int ret = -1;

        try {
            ProcessBuilder builder = new ProcessBuilder(command);
            if (!TextUtils.isEmpty(outputFile)) {
                builder.redirectOutput(new File(outputFile));
            }

            Process process = builder.start();
            ret = process.waitFor();
        } catch (InterruptedException | IOException var5) {
            var5.printStackTrace();
        }

        return ret;
    }

    public static void run(String[] objdumpCmd, String outputFile) {
        run_linux(objdumpCmd, outputFile);
    }
}
